const Sequelize = require('sequelize');
const file = require('../models/model/file');
const folder = require('../models/model/folder');


/**
 * 通过文件id查询单个文件
 * @param {文件id} fileId 
 * @param {文件夹id} folderId
 */
exports.findBackstageSingleFile = async (folderId = '', fileId = '') => {
    const ins = await file.findOne(
        {
            where: {
                id: fileId,
                folderId
            }
        }
    )
    if (ins) {
        return ins;
    }
    return null;
}

/**
 * 通过文件夹id查询单个文件夹
 * @param {*} folderId 
 */
exports.findBackstageSingleFolder = async (folderId = '') => {
    const ins = await folder.findOne(
        {
            where: {
                id: folderId
            }
        }
    )
    if (ins) {
        return ins;
    }
    return null;
}

/**
 * 更新文件的内容
 * @param {文件夹id} folderId 
 * @param {文件id} fileId 
 * @param {内容} content 
 * @param {标题} name 
 */
exports.updateBackstageSingleFile = async (folderId = '', fileId = '', content = '', name = '') => {
    return await file.update(
        {
            name,
            content
        },
        {
            where: {
                id: fileId,
                folderId,
            }
        }
    )
}